package taobao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class delete {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n + 2]; // 1-based, extra for bounds
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
        }

        boolean[] left = new boolean[n + 2];
        boolean[] right = new boolean[n + 2];

        left[0] = true;
        for (int i = 1; i <= n; i++) {
            left[i] = left[i - 1] && a[i] >= a[i - 1];
        }

        right[n + 1] = true;
        for (int i = n; i >= 1; i--) {
            right[i] = right[i + 1] && a[i] <= a[i + 1];
        }

        int count = 0;
        for (int l = 1; l <= n; l++) {
            for (int r = l; r <= n; r++) {
                boolean okLeft = (l == 1) || left[l - 1];
                boolean okRight = (r == n) || right[r + 1];
                boolean okMerge = (l == 1 || r == n) || a[l - 1] <= a[r + 1];
                if (okLeft && okRight && okMerge) {
                    count++;
                }
            }
        }

        System.out.println(count);
    }
}
